package chapter_6;

public class Test  {

    public static int test(String s){
        int lenght = 0;
        try{

            System.out.println("before  exception");
            lenght = s.length();
//            int i = 5/0;
            int[] arr = new int[5];
            System.out.println(arr[9]);
            System.out.println("after exception");

        }catch (NullPointerException e){
            int i =  9 /0;
            System.out.println("发生了异常");
        }catch (ArithmeticException e){
            System.out.println("算术异常");
        }catch (Exception e){
            System.out.println("异常");
        }finally{
            //in.close();
            System.out.println("回收资源");
        }
        System.out.println("结束");
        //in.close();
        return lenght;
    }

    public static void main(String[] args) {
        test("aaaa");
    }

    public static void main1(String[] args) throws ArithmeticException {
        int a = 10;
        int b = 0;
        try{
            System.out.println("异常发生前");
            int i = a / b;//抛出异常
            System.out.println("异常后的");//异常
            //close
        }catch (Exception e){
            System.out.println(e.toString());
            e.printStackTrace();
            System.exit(1);
            System.out.println("异常被捕获了");
        }finally {
            //close
            System.out.println("finally");
        }
//        int i = a / b;
        System.out.println("aaaa");
    }
}
